package com.cass.controller;


import com.cass.entity.BreakTheRule;
import com.cass.service.IBreakTheRuleService;
import com.cass.uilts.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 违纪情况类 控制器
 *
 * @Author: wangyou
 */
@Slf4j
@RestController
@RequestMapping("/breakTheRule")
@RequiredArgsConstructor
@Tag(name = "BreakTheRuleController", description = "违纪情况")
public class BreakTheRuleController {

    private final IBreakTheRuleService breakTheRuleService;

    private static final Logger logger = LoggerFactory.getLogger(StudentController.class);
    /**
     * 获取所有学生违纪
     *
     */
    @Operation(summary = "获取所有学生违纪", description = "需要登录后访问")
    @ApiResponse(description = "返回获取所有学生违纪", content = @Content(mediaType = "application/json", schema = @Schema(implementation = BreakTheRule.class)))
    @GetMapping()
    public Result<List<BreakTheRule>> getBreakTheRule() {
        logger.info("获取所有学生违纪");
        return Result.success(breakTheRuleService.list());

    }
    /**
     * 添加学生违纪
     *
     */
    @PostMapping()
    public Result<String> addBreakTheRule(@RequestBody BreakTheRule breakTheRule) {
        logger.info("添加学生违纪");
        breakTheRuleService.save(breakTheRule);
        return Result.success("添加学生违纪成功");
    }
    /**
     * 修改学生违纪
     *
     *
     */
    @PutMapping()
    public Result<String> updateBreakTheRule(@RequestBody BreakTheRule breakTheRule) {
        logger.info("修改学生违纪");
        breakTheRuleService.updateById(breakTheRule);
        return Result.success("修改学生违纪成功");
    }
    /**
     * 删除学生违纪
     *
     *
     */
    @DeleteMapping("/{id}")
    public Result<String> deleteBreakTheRule(@PathVariable Integer id) {
        logger.info("删除学生违纪");
        breakTheRuleService.removeById(id);
        return Result.success("删除成功");
    }
    /**
     * 批量删除学生违纪
     *
     *
     */
    @DeleteMapping("/batchDelete")
    public Result<String> batchDelete(@RequestBody List<Integer> ids){
        logger.info("批量删除学生信息：{}", ids);
        breakTheRuleService.removeByIds(ids);
        return Result.success("批量删除成功");
    }
}
